<template>

    <div class="aaa">
        <div class="fatieanniu">
            <el-button   @click="dianji" type="success" >发表文章</el-button>
        </div>
        <div class="tishi">
            ---以下是帮您搜索到的关于 {{content}} 的文章内容---
        </div>
               <!--                  内容-->
        <div class="jinrirediang1" v-for="(p,index) in sousuowenzhang" :key="index">
            <!--            帖子标题-->

            <!--                一条帖子的框框，从这里开始v-for遍历-->
            <div class="rediang1" >
                <router-link :to="{name:'wenzhangxiangqing',
                                 query:{id:p.id,
                                        title:p.title,
                                        content:p.content,
                                        time:p.time
                                 }}">


                    <div class="zuixintiezi2" >
                        {{p.title}}
                    </div>
                    <div class="contentcss">
                        <div v-html="p.content.length > 100 ? p.content.slice(0, 100) + '...' :p.content" />
                    </div>
                    <div class="xianshicount">
                        👍{{p.countGetLike}}  ☆{{p.countCollect}}   👀{{p.countLook}}
                    </div>


                </router-link>
            </div>
        </div>
        <el-row style="font-size: 30px ;margin-top: 100px">
            <!--     分页     -->
            <el-pagination
                    v-show="total>0"
                    :page-size="pageSize"
                    :pager-count="11"
                    :current-page.sync="pageNum"
                    :total="total"
                    @current-change="chaxunwenzhan"
            >
            </el-pagination>

        </el-row>

        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="文章作者" prop="userName">
                    <el-tag type="info" effect="plain">{{form.userName}}</el-tag>
                    <!--                        <el-input v-model="form.userName" placeholder="请输入文章笔名" />-->
                </el-form-item>
                <el-form-item label="文章标题" prop="title">
                    <el-input v-model="form.title" placeholder="请输入文章标题" />
                </el-form-item>
                <el-form-item label="文章内容">
                    <editor v-model="form.content" :min-height="192"/>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="fawentijiao">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import Editor from '@/components/Editor';
    export default {
        name: "suosuowengzhang",
        components: {
            Editor,
        },
        data(){
            return{
                sousuowenzhang:[],
                form: {
                    title:'',
                    content:'',
                    time:'',
                    userName:'',
                    userId:'',
                    pageSize: 10,
                    pageNum: 1,
                    total: 0,
                },
                // 表单校验
                rules: {},
                // 修改对话框开关控制
                open :false,
                title:'发布文章',
                shiyisheng: false,
            }
        },
        created() {
            this.chaxunwenzhan();

        },
        methods:{
            async getuserlll(){
                const {data:jieguo}=await this.$http.get('user/info',{headers:{
                        'Authorization':window.sessionStorage.getItem('token')
                    }})
                this.shiyisheng=jieguo.data.userRole
                this.form.userName=jieguo.data.basicUserInformation.username
                this.form.userId=jieguo.data.basicUserInformation.id
                this.basicUserInformation=jieguo.data.basicUserInformation
            },
            async chaxunwenzhan(){
                console.log("文章接口"+this.content);
                const {data:jieguo}=await this.$http.get("/article/userList?content="+this.content)
                this.sousuowenzhang = jieguo.data.data;
                this.total = jieguo.data.total;
            },
            //点击打开发布文章对话框
            dianji(){
                this.getuserlll();
                if(this.shiyisheng == '医生'){
                    this.open=true;
                    console.log("open")
                }
                else if(this.shiyisheng == '')
                    this.open=false
                else
                    this.$message("暂时未获取该权限，详情请联系管理员")
            },
            /** 提交按钮 */
            tijiao() {
                const token = sessionStorage.getItem("token");
                this.$http.defaults.headers.common['Authorization'] = token;
                this.$http.post('article/insertArticle', this.form).then(response => {
                    console.log(response)
                    if (response.data.code === 200) {
                        this.$message({showClose: true, message: "修改成功", type: "success"})
                        this.open = false;
                        this.getwenzhang()
                    }
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form.title=''
                this.form.content=''
                this.form.time=''
            }
        },
        mounted() {
            //初始化
            this.chaxunwenzhan();

        },
        props: {
            "content": {
                required: true,
                default: () => ""
            },
        },
        watch: {
            "content": {
                handler(newValue) {
                    if (newValue === "") {
                        this.yinshilist = []
                        this.total = 0
                        return
                    }
                    this.content = newValue;
                    this.chaxunwenzhan();
                },
                deep: true
            }


        },
    }
</script>

<style scoped>
    .aaa{
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: scroll;
        min-height: 850px;
        width: 100%;
        /*height: auto!important;*/
        /*background: #409EFF;*/
    }
    .jinrirediang1{
        height: 200px;
        width: 100%;
        /*margin-bottom: 50px;*/
    }
    /*最新帖子标题的样式*/
    .zuixintiezi2{
        height: 20%;
        margin-left: 20px;
        text-align: left;
        color: black;
        /*line-height: 2em;*/
        font-size: 18px;
        color: #111111;
    }
    .rediang1{
        border: #FFFACD solid 2px;
        background: #FFFFE0;
        margin-top: 20px;
        margin-left: 12%;
        width: 76%;
        height: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #111111;
    }
    .contentcss{
        height: 50%;
        color: #111111;
    }
    .xianshicount{
        height: 15%;
        color: #111111;
        float: right;
    }
    .el-button{
        margin-left: 80%;
    }
    .fatieanniu{
        width: 100%;
        height: 30px;
    }
    .tishi{
        width: 100%;
        height: 50px;
        color: #888888;
        font-size: 30px;
        text-align: center;
    }
</style>
